//
//  STOrderStatisticsVC.m
//  YiYueHairdresser
//
//  Created by zhouzhouzhou on 2018/10/11.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STOrderStatisticsVC.h"
#import "STOrderStatisticsView.h"
#import "YLTimePickView.h"

@interface STOrderStatisticsVC ()<STOrderStatisticsViewDelegate>{
    UITableView * statisticsTableView;
    NSDictionary * statisticsDic;
    STOrderStatisticsView * orderStatisticsView;
    STOrderCountModel * countModel;
    STOrderSumCountSumModel * sumCountModel;
    NSString * startTime ;
    NSString * endTime ;
    NSInteger hairType; //0 入驻 1 签约 2全部
}
@property (strong ,nonatomic) STOrderStatisticsView * orderStatisticsView;
@end

@implementation STOrderStatisticsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"订单统计";
    //
    [self wr_setNavBarBarTintColor:[UIColor whiteColor]];
    [self wr_setNavBarTintColor:[UIColor blackColor]];
    
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    hairType = 2;
    [self loadOrderStatisticsView];
    [self loadOrderStatisticsData];
}



-(void)loadOrderStatisticsData{
    [STHairService getStylistOrderCount:^(id result, NSError *error) {
        if (error) {
            [ZYHCommonMethod showError:error];
        }
        countModel =[STOrderCountModel modelWithJSON:result];
        [orderStatisticsView reloadOrderCountView];
    }];
    
    [STHairService getStylistSuccessOrdersWithFrom:orderStatisticsView.starTime end:orderStatisticsView.endTime completion:^(id result, NSError *error) {
        if (error) {
            [ZYHCommonMethod showError:error];
        }
        sumCountModel =[STOrderSumCountSumModel modelWithJSON:result];
        NSArray * arrModel = [NSArray arrayWithObjects:sumCountModel, nil];
        orderStatisticsView.listData = arrModel;
        [orderStatisticsView reloadOrderListView];
    }];
}

- (void)loadOrderStatisticsView{
    orderStatisticsView = [[STOrderStatisticsView alloc]initWithFrame:self.view.bounds];
    orderStatisticsView.orderInfoData = @{};
    
    //获取当前月份 和前一月份
    NSDate * nowDate = [NSDate date];
    NSString * nowMonth = [nowDate stringWithFormat:@"yyyy-MM-dd"];
    NSDate * lastMonthDate = [nowDate dateByAddingMonths:-1];
    NSString * lastMonth = [lastMonthDate stringWithFormat:@"yyyy-MM-dd"];
    orderStatisticsView.starTime = lastMonth;
    orderStatisticsView.endTime = nowMonth;
    startTime =lastMonth;
    endTime =nowMonth;
    orderStatisticsView.delegate = self;
    [orderStatisticsView setOrderStatisticsListView];
    [self.view addSubview:orderStatisticsView];
    _orderStatisticsView = orderStatisticsView;
    
}


-(void)orderStatisticsViewDidSelCellIndexPath:(NSIndexPath *)indexPath{
}

-(void)orderStatisticsViewSelType:(NSInteger)selType{
    if (selType ==0) {
        hairType = 2;
    }else if (selType ==1) {
        hairType = 0;
    }else if (selType ==2) {
        hairType = 1;
    }
}

-(void)orderStatisticsViewSureSelectCondition{
    [self loadOrderStatisticsData];
    
}

-(void)orderStatisticsViewChangeDay:(NSDictionary *)dayDic type:(NSString *)type{
    YLTimePickView * pickView = [[YLTimePickView alloc] init];
    pickView.defDateStr = [dayDic valueForKey:@"data"];
    pickView.selectDateB = ^(NSString *date) {
        if([type isEqualToString:@"end"]){
            orderStatisticsView.endTime = date;
            endTime =date;
        }else if([type isEqualToString:@"from"]){
            orderStatisticsView.starTime = date;
            startTime =date;
        }
        [orderStatisticsView reloadTimerOrType];
    };
    [pickView show];
}

@end
